<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 *
 *
 *
 * @package     h
 * @subpackage  models
 * @category    models
 * @author      hyw
 * @copyright   copyright (c) 2012
 * @filesource
 */
class Shop_point_model extends Base_model {

    protected $_table_name = 'shop_point';
    protected $_key_name = 'shop_point_id';

    function get_info($id) {
        if (!empty($id))
            $where[$this->_key_name] = $id;
        $where["dtime"] = 0;
        return $this->fetch(NULL, $where, NULL, 'row');
    }

    function get_all() {
        $where = array("dtime" => 0);
        return $this->fetch(NULL, $where);
    }

    function query_keyword($keyword = "", $limit) {
        $this->set_or_like('name,code,unified_numbering,phone', $keyword);
        $this->set_limit($limit);
        $where["dtime"] = 0;
        return $this->fetch(NULL, $where);
    }

    function query_keyword_count($keyword = null) {
        $this->set_or_like('name,code,unified_numbering,phone', $keyword);
        $con["where"][] = array("dtime" => 0);
        $this->set_args_array($con);
        return $this->fetch_count();
    }

    function update_data($data) {
        $value = array('name' => $data['name'], 'code' => $data['code'], 'unified_numbering' => $data['unified_numbering'], 'phone' => $data['phone'], 'address' => $data['address'], 'mtime' => time());
        $where[] = array($this->_key_name => $data['id']);
        return $this->update($value, $where);
    }

    function add($data) {
        $data["ctime"] = time();
        return $this->insert($data);
    }

    function del($data) {
        
        $value = array("dtime" => time());
        $this->db->where($this->_key_name, $data['id']);
        $this->db->update($this->_table_name, $value);
        return 1;
        //$where = array($this->_key_name => $data['id']);
        //$value = array("dtime" => time());
        //return $this->update($value, $where);
    }

}
